<%-- 
    Document   : carlist
    Created on : 2014/2/24, 下午 04:46:02
    Author     : Gjun
--%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashMap"%>
<%
    ArrayList carlist = (ArrayList)session.getAttribute("carlist");
     String index = request.getParameter("index");
            if(index!=null)
            {  carlist.remove(Integer.parseInt(index));
                
            }
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
        <title>您的購物車</title>
    </head>
    <body >
    
        <form action="carlist.jsp" id="delform" method="post" >
            <input type="hidden" name="index" id="index" value="">
        </form>
          <%
            
            if(session.getAttribute("person")==null){
                 out.println("請先登入");
               
             }else if(carlist==null)
             {  out.println("尚未放入商品喔!");}
             else {
            for(int i =0;i<carlist.size();i++)
             { 
              HashMap map =(HashMap)carlist.get(i);
                out.println("編號 :"+(i+1)+"<br>" +"產品名: "+
                        map.get("product_name")+"<br>"+"產品價格: "+
                        map.get("product_price")+"<br>"+"庫存量: "+
                        map.get("product_stock")+
                        "<br>"+
                        " <input type='button' value='刪除' onclick='del("+i+")'>"
                );
              out.println("<br>");
             }
         
        %>
      
      
        <h1><a href="#" onclick="cash()">結帳去</a></h1>
        <%
         }
            %>
        <script>
               function del(i)
            {     
                     window.document.getElementById("index").value=i;
                     window.document.getElementById("delform").submit();
                    // window.location.href="carlist.jsp";  
            }
             // document.location.reload(true)
       
           function cash()
          {
           window.open("cash.jsp","結帳頁");
          }
       //var t= setTimeout('re()',1000);
      //window.scrollTo(100,500)
         function re()
    {  
        window.location.href="carlist.jsp" 
    }
        </script>
      
    </body>
</html>
